/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : type.h
  * @brief          : New type definition.
  * @author         : Qilong Huang <jcdiyhelp@qq.com>
  * @date           : 2021-06-08 
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2021 Joy create tech(Suzhou, China) Co., Ltd.
  * All rights reserved.
  *
  *
  ******************************************************************************
  */
 /* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TYPE_H
#define __TYPE_H

#ifdef __cplusplus
extern "C" {
#endif

/* Global include ---------------------------------------------------------*/
#include "global.h"

/* Global type declaration ---------------------------------------------------------*/

/* Function retrun type define */
typedef enum
{
    TYP_SUCCESS            = 0,
    TYP_FAIL               = 1,
    TYP_ADDRESS_OVERFLAOW  = 2,
    TYP_ADDRESS_NOT_ALLIGN = 3
} TYP_funcRetrun_t;

/* Boolen type define*/
typedef enum
{
    TYP_FALSE = 0,
    TYP_TRUE = 1,
} TYP_BOOL;
#define true                        TYP_TRUE
#define false                       TYP_FALSE
#define BOOL                        TYP_BOOL

/* Define memory key work */
#define TYP_MEMORY                  volatile      

/* Define the USART buffer length is 16 */
#define MAX_USART_LEN               26
#define MAX_USART_BUF               0x08

/* Common data type definition */
typedef unsigned char               UINT8_t;
typedef char                        SINT8_t;
typedef unsigned short int          UINT16_t;
typedef signed short int            SINT16_t;
typedef unsigned long int           UINT32_t;
typedef signed long int             SINT32_t;
             
 

/** Vector Table of STM32 controller. */
typedef struct 
{
	UINT32_t initial_sp_value;	/**< Initial SP value 		*/
	void (*reset)(void);	/**< Reset vector 			*/
	UINT32_t vectors[105]; 		/**< other vectors 			*/
	struct bis const *bis;		/**< Address of BIS header 	*/
} TYP_stm32VectorTable;

/*Information table type*/
typedef struct 
{
    UINT8_t index;
    UINT32_t EepStartAddress;
    UINT8_t *VarAddress;
    UINT8_t SpaceLen;
    UINT8_t Attribute;
} TYP_InfoTab_t;


/*Usart receive singal frame type*/
typedef struct 
{
    UINT8_t data[MAX_USART_LEN];
    UINT8_t data_pt;
} TYP_UsartCell_t;

/*Usart receive buffer type*/
typedef struct 
{
    TYP_UsartCell_t BufferBody[MAX_USART_BUF];
    volatile UINT8_t BufferHead;
    volatile UINT8_t BufferTail;
} TYP_UsartBuffer_t;

/* Define cmd union*/
typedef union 
{
    struct type
    {
        UINT8_t OpDate      : 4;
        UINT8_t EEP_Flag    : 2;
        UINT8_t OpCode      : 2;
    } Cmd_Str;
    UINT8_t Cmd_U8;
} TYP_ProtCmd_t;

/* Define address union*/
typedef union 
{
    UINT8_t Address_U8[4];
    UINT32_t Address_U32;
} TYP_RegAddress_t;

/* Define usart signal frame format*/
typedef struct 
{
    UINT8_t StartByte[2];
    UINT8_t Length;
    TYP_ProtCmd_t Cmd;
    TYP_RegAddress_t Addr;
    UINT8_t Data[16];
    UINT8_t Crc[2];
} TYP_SingalFrame_t;


typedef struct 
{
    UINT32_t FlashData[32];
    UINT8_t FlashDataPt;
    UINT8_t FlashFrameNumber;
} TYP_FlashHalfPage_t;

typedef enum
{
    RESP_OK        = 0,
    RESP_CRC_ERR   = 1,
    RESP_FLASH_ERR = 2
} TYP_SPResp_t;
/*App program function pointer definition*/
typedef void (*TYP_drcPtr)(void); //Define the jump pointer
#ifdef __cplusplus
}
#endif

#endif /* __TYPE_H */